<?php
define('ADMIN', 'admin');
define('ADMINPX', 'adminpx');
$time30=strtotime(date("Y-m-d H:i:s",strtotime(" +30 minute")));
$smoe=$_GET['smoe'];
$admin_pwss=$_COOKIE['admin_pwss'];
$admin_ip  =$_COOKIE['admin_ip'];
$admin_time=$_COOKIE['admin_time'];
$admin_logi=$db->get_one('user',"`pwss` = '$admin_pwss' and `user_qx` = '1' ",'');
if(!$admin_logi or $admin_time < $time){
		$action='login';
		setcookie('admin_pwss','');
		setcookie('admin_time','');
}else{
	  $admin_uid=$admin_logi[uid];
	  $admin_name=$admin_logi[name];
    setcookie('admin_time',$time30);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="Cache-Control" content="no-cache" />
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; minimum-scale=1.0; user-scalable=no;" />
<title><?php echo $bzxtname.' - '.$bzxtnamey.' - 后台管理中心'; ?></title>
<meta name="keywords" content="<?php echo $bzxtname.'程序版本号：'.$bzxtvbb; ?>"/>
<meta name="description" content="<?php echo $bzxtname.'程序升级时间:'.$bzxtvsj; ?>"/>
<meta name="copyright" content="Copyright (c) 2010-2015 Tencent.">
<link href="source/admin/admin_css.css"rel="stylesheet"type="text/css"/>
<script type="text/javascript">
function checkAll(type, form, value, checkall, changestyle) {
	var checkall = checkall ? checkall : 'chkall';
	for(var i = 0; i < form.elements.length; i++) {
		var e = form.elements[i];
		if(type == 'option' && e.type == 'radio' && e.value == value && e.disabled != true) {
			e.checked = true;
		} else if(type == 'value' && e.type == 'checkbox' && e.getAttribute('chkvalue') == value) {
			e.checked = form.elements[checkall].checked;
			if(changestyle) {
				multiupdate(e);
			}
		} else if(type == 'prefix' && e.name && e.name != checkall && (!value || (value && e.name.match(value)))) {
			e.checked = form.elements[checkall].checked;
			if(changestyle) {
				if(e.parentNode && e.parentNode.tagName.toLowerCase() == 'li') {
					e.parentNode.className = e.checked ? 'checked' : '';
				}
				if(e.parentNode.parentNode && e.parentNode.parentNode.tagName.toLowerCase() == 'div') {
					e.parentNode.parentNode.className = e.checked ? 'item checked' : 'item';
				}
			}
		}
	}
}
</script>
</head>
<body>
<div class="body">
<?php
echo '<div class="head">'.$bzxtname.' <font color="#000000">X</font> <font color="#FF0000">'.$bzxtvbb.'</font> '.$bzAuthorize.' - 网站管理中心</div>';
function foot(){
	global $bzxtnamey,$bzxtvbb;
echo <<<end
<div class="foot"><a href="admin.php?">后台首页</a> - <a href="index.php?">网站首页</a></div>
<div class="footer">
Powered by <b>$bzxtnamey</b> X $bzxtvbb   2010-2015<br/>
<font color="#00CC33">技术QQ：2442072408</font><br />
</div>
</div>
</body>
</html>
end;
}
function admin_pdzh(){
	global $admin_uid;
  if($admin_uid == '1000'){
     $tables='1';
  }
  return $tables;
}
function deldir($dir){
   $dh = opendir($dir);
   $a='0';
   while ($file = readdir($dh)){
      if ($file != "." && $file != ".."){
         $fullpath = $dir . "/" . $file;
         if (!is_dir($fullpath)){
            unlink($fullpath);
            @rmdir($fullpath);
            $a++;
         } else{
            $b=deldir($fullpath);
            @rmdir($fullpath);
            $a=$a+$b;
         }
      }
   }
   closedir($dh);
   return $a;
}
function list_tables($database){
	global $_config;
	$ssid=explode("_","".$_config['mysql']['qianh']."");
  $rs = mysql_list_tables($database);
  $tables = array();
  while ($row = mysql_fetch_row($rs)) {
	  $sjkbb=explode("_",$row[0]);
  	if($ssid[0] == $sjkbb[0]){
       $tables[]= $row[0];
    }
  }
  mysql_free_result($rs);
  return $tables;
}
function get_insert_sql($table, $row){
  $sql = "INSERT INTO `{$table}` VALUES (";
  $values = array();
  foreach ($row as $value) {
    $values[] = "'" . mysql_real_escape_string($value) ."'";
  }
  $sql .= implode(', ', $values) . ");\r\n";
  return $sql;
}
function sjk_sql($name,$nameb){
	global $_config,$url;
   $mysqldatabase=$_config['mysql']['database'];
   $bnsjkname="$name/".$nameb."_1.sql";
   $fp = fopen($bnsjkname , 'a+');
   $tables = list_tables($mysqldatabase);
  foreach ($tables as $a=>$table) {
   if(!$p){$p=1;}
   $sjkname="$name/".$nameb."_$p.sql";
   $fp = fopen($sjkname , 'a+');
   if($a=='1'){fwrite($fp, $sjkbfts);}
   $a=mysql_query("show create table `{$table}`");
   $row=mysql_fetch_assoc($a);
   $heyjdi="DROP TABLE IF EXISTS `$table`;\r\n".$row['Create Table'].";\r\n";
   $pppp+=strlen($heyjdi);
   fwrite($fp,"$heyjdi");
   $rs =mysql_query("SELECT * FROM `{$table}`");
   while ($row = mysql_fetch_row($rs)) {
   	 $mmmmrr=get_insert_sql($table,$row);     
     $pppp+=strlen($mmmmrr);
     if(round($pppp/1000/1000,3) > '2'){
     	 $p++;
     	 $pppp=0;
       fclose($fp);
       $sjkname="$name/".$nameb."_$p.sql";
       $fp = fopen($sjkname , 'a+');
       fwrite($fp, $sjkbfts);
       fwrite($fp, $mmmmrr);
     }else{
       fwrite($fp, $mmmmrr);
     }
   }
   mysql_free_result($rs);
  }
  return $p;
}

function read_file($filename,$method="rb"){
     if($handle=@fopen($filename,$method)){
         @flock($handle,LOCK_SH);
         $filedata=@fread($handle,@filesize($filename));
         @fclose($handle);
     }
return $filedata;
}
function hfsjk_sql($file,$replace=''){
global $_config;
       if($replace == '1'){
       	    $readfiles=$file;
       }else{
       	    $readfiles=read_file($file);
       }
       if($readfiles){
          $readfiles=str_replace('bz_',$_config['mysql']['qianh'],$readfiles);
       }
       $detail=explode("\n",$readfiles);
       $count=count($detail);
       for($j=0;$j < $count;$j++){
           $ck=substr($detail[$j],0,4);
           if( ereg("#",$ck)||ereg("--",$ck) ){
           continue;
       }
       $array[]=$detail[$j];
       }
       $read=implode("\n",$array); 
       $sql=str_replace("\r",'',$read);
       $detail=explode(";\n",$sql);
       $count=count($detail);
       $s='0';
       $f='0';
       $check='0';
       for($i=0;$i< $count;$i++){
           $sql=str_replace("\r",'',$detail[$i]);
           $sql=str_replace("\n",'',$sql);
           $sql=trim($sql);
           if($sql){
	               if(mysql_query($sql)){
		                $s++;
		             }else{
		       	        $f++;
                    mysql::show('mysql_cw:',$query);
			           }
                 $check++;
           }
       }
      return "处理<font color='#FF0000'>$check</font>条命令 。成功<font color='#FF0000'>$s</font>条，失败<font color='#FF0000'>$f</font>条。";
}
function zip($tmp_name,$new_name){
				global $have_zip_file;
      $zip = @new ZipArchive; 
      $res = @$zip->open($tmp_name); 
      if ($res === TRUE) { 
          $zip->extractTo($new_name); 
          $zip->close(); 
					@unlink($tmp_name);
          return $new_name;
      } 
}
?>